<template>
	<view class="content">
		<u-navbar back-text="" title="">
			<view style="width: 100%;display: flex;justify-content: center;font-weight: bold;font-size: 34rpx;">
				分享好友
			</view>
			<view style="margin-right: 50rpx;">

			</view>
		</u-navbar>


		<view style="width: 100%;display: flex;flex-direction: column;padding: 20rpx;background: white;">
			<view @click="clickuser(item)"
				style="width: 100%;display: flex;align-items: flex-start;margin-bottom: 20rpx;margin-top: 10rpx;"
				v-for="(item,k) in list.filter(e=>e.fid != id)">
				<view>
					<u-avatar v-if="item.gid == 0" mode="square" size="90"
						:src="$store.state.common.systemInfo.fileurl + 'avatar/' + item.fid + '.jpg'"></u-avatar>
					<bgyx-group-avatar :id="item.gid" v-else />
				</view>
				<view
					style="flex: 1;display: flex;justify-content: space-between;align-items: center;padding: 0rpx 20rpx 10rpx 20rpx;height: 100rpx;border-bottom: 1rpx solid #e1e1e155;">
					<view style="display: flex;flex-direction: column;flex: 1;">
						<view
							style="font-weight: bold;font-size: 30rpx;width: 100%;display: flex;justify-content: space-between;">
							<view style="font-size: 32rpx;">
								{{item.name}}
							</view>
							<view style="font-size: 20rpx;color: #c6c6c6;font-weight: normal;">
								<image v-if="haveue(item)" src="/static/images/checked.png"
									style="width: 40rpx;height: 40rpx;" mode=""></image>
								<image v-else src="/static/images/check.png" style="width: 40rpx;height: 40rpx;"
									mode=""></image>
							</view>
						</view>
						<view style="font-size: 25rpx;color: #999;margin-top: 8rpx;width: 500rpx;" class="u-line-1">
							<bgyx-msg-display :info="item" />
						</view>
					</view>

				</view>
			</view>

		</view>


	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		pub
	} from '../../common/event';
	import moment from 'moment';
	export default {
		data() {
			return {
				scrollTop: '',
				groupusers: [],
				grids: [],
				id: '',
				name: ''
			}
		},
		components: {

		},
		computed: {
			...mapState({
				list: (state) => {
					return state.friend.list.filter(e => e.status != '拉黑' && e.status != '被拉黑' && e.status !=
						'被删除')
				}
			})
		},
		onLoad({
			id,
			name
		}) {
			this.id = id
			this.name = name
		},
		methods: {
			clickuser: async function(e) {
				console.log(e)
				const user = this.$store.state.user.user
				const data = {
					"name": user.name,
					"uid": user.id,
					"toid": e.gid > 0 ? 0 : e.fid,
					"toname": e.gid > 0 ? '' : e.name,
					"gid": e.gid > 0 ? e.gid : 0,
					"gname": e.gid > 0 ? e.name : '',
					"type": "usercard",
					"content": this.name,
					"timelong": this.id,
					"time": moment().valueOf(),
					"money": 0,
					"status": "正常",
					"note": ""
				}
				console.log(data)
				if(e.gid == 0){
					const ret = await this.$u.post(`chat/chat/sendMessage`, data)
					
					data.id = ret.data
					console.log(ret)
					this.$store.commit(`message/addMessage`, data)
					
					uni.showToast({
						title: "已分享"
					})
					
					uni.navigateBack()
				}else{
					const ret = await this.$u.post(`chat/chat/sendGMessage`, data)
					
					data.id = ret.data
					console.log(ret)
					
					uni.showToast({
						title: "已分享"
					})
					
					uni.navigateBack()
				}
				
			},
			haveue: function(e) {
				return this.grids.includes(e.id)
			},
			sends: async function() {
				console.log(this.grids)
				console.log(this.groupusers)
				const targets = this.groupusers.map(e => {
					return {
						fid: e.fid,
						uid: e.uid,
						gid: e.gid,
					}
				})
				const user = this.$store.state.user.user
				const ret = await this.$u.post(`chat/chat/shareMessage`, {
					id: this.id,
					uid: user.id,
					targets
				})
				uni.navigateBack()
			},
		}
	}
</script>


<style scoped>
	page {
		background: white;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
	}
</style>